<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="lib/jquery-3.4.1.js"></script>
    <script src="lib/http.js"></script>
    <style>
        *{margin:0;padding:0}
        .item img{
            width:200px;
            border:1px solid #ff2d51;
        }
        #app{
            display:flex;
            justify-content: space-between;
            flex-wrap: wrap;
        }
    </style>
</head>

<body>
    <!-- <img src="images/giphy.gif" alt="" id=".loading"> -->
    <div id="app"></div>
    <div class="loading"></div>
    <script>
        var offset=0;
        http({
            callback: handleData,
            data: {
                offset,
            }
        })

        function handleData(res) {
            // console.log(res)
            var { playlists } = res;
            var musics = []
            playlists.forEach((item, index) => {
                var obj = {}
                var { name, coverImgUrl } = item;
                obj.name = name.splice(0,8)+"...";
                obj.imgUrl = coverImgUrl;
                musics.push(obj)
                // console.log(musics)
            });

            for(let i=0;i<musics.length;i++){
               var item = `<div class="item">
                <img src="${musics[i].imgUrl}"/>
                <p>${musics[i].name}</p>
                </div>`
               $("#app").append(item)
           }
           $(window).scroll(function(){
               if(onReachBottom()){
                   offset+=35;
                   http({
                       callback:handleData,
                       data:{
                           offset
                       }
                   })
               }
           })
        }
    </script>
</body>

</html>